#include<iostream>
#include<cctype>
using namespace std;
const int SLEN = 30;
struct student{
    char fullname[SLEN];
    char hobby[SLEN];
    int opplevel;
};
// getinfo() 有两个参数：
// 一个是指向 student 结构体数组的第一个元素的指针，
// 另一个是表示数组大小的整数。
// 该函数可以获取学生的信息并且将信息存储在数组中。
// 当数组被填满或者在输入学生姓名是输入了一行空行时，该函数将会被停止，
// 并返回实际存储的学生数量。
int getinfo(student pa[],int n);

// display1() 输入学生结构体，显示结构体的内容。
void display1(student st);

// display2() 输入学生结构体的地址，显示该结构体的内容。
void display2(const student *ps);


// display3() 输入学生结构体数组的第一个元素的地址和数组大小，显示结构体的内容。
void display3(student pa[],int n);
int main()
{
    cout << "Enter class size: ";
    int class_size;
    cin >> class_size;
    while(cin.get() != '\n')
    {
        continue;
    }

    student *ptr_stu = new student[class_size];
    int entered = getinfo(ptr_stu,class_size);
    for (int i = 0; i< entered;i++)
    {
        display1(ptr_stu[i]);
        display2(&ptr_stu[i]);
    }
    display3(ptr_stu,entered);
    delete []ptr_stu;
    cout<<"Done"<<endl;
    return 0;
}

int getinfo(student pa[],int n)
{
    for ( int i = 0; i < n; i++)
    {
        cout << "Enter the fullname of student:";
        cin.getline(pa[i].fullname,SLEN);

        //black lines are skipped.
        int judge = 0;
        for ( int j = 0; pa[i].fullname[j] != '\0'; j++)
        {
            if ( !isspace(pa[i].fullname[j]))
            judge++;
        }
        if ( !judge)
        return i;

        cout << "Enter the hobby of student:";
        cin.getline(pa[i].hobby,SLEN);
        cout << "Enter the opposite basis level of student:";
        (cin >> pa[i].opplevel).get();
    }
    return n;
}

void display1(student st)
{
    cout << endl << "Enter the student structure to display the content of the structure." << endl; 
    cout << st.fullname << "\t" << st.hobby << "\t" << st.opplevel << endl;
}

void display2(const student* ps)
{
    cout << endl << "Enter the address of the structure to display the content of the structure." << endl;
    cout << ps->fullname << "\t" << ps->hobby << "\t" << ps->opplevel << endl;
}

void display3(student pa[],int n)
{
    cout << endl << "Enter the address and array size of the first the element of the student structure array to display the contents of the structure. " << endl;
    for ( int i = 0; i < n; i++)
    {
        cout << pa[i].fullname << "\t" << pa[i].hobby << "\t" << pa[i].opplevel << endl;
    }
}